package com.adinnet.api.common.model;


import com.adinnet.api.user.model.User;

import java.util.HashMap;


public class AuthUtil {
    private static ThreadLocal<HashMap<String, Object>> threadLocal = new ThreadLocal<HashMap<String, Object>>() {
        @Override
        protected HashMap<String, Object> initialValue() {
            return new HashMap<String, Object>();
        }
    };

    private static final String LOGIN_KEY = "loginUser";

    public static void clear() {
        threadLocal.remove();
    }

    public static void setLoginUser(Object user) {
        threadLocal.get().put(LOGIN_KEY, user);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    public static User getLoginUser() {
        Object value = threadLocal.get().get(LOGIN_KEY);
        return value == null ? null : User.class.cast(value);
    }


}
